package com.shop.dingdongshoppingapi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.dingdongshoppingapi.dao.HistoryDao;
import com.shop.dingdongshoppingapi.dto.HistoryAddDto;
import com.shop.dingdongshoppingapi.entity.History;
import com.shop.dingdongshoppingapi.service.intf.HistoryService;
import com.shop.dingdongshoppingapi.vo.R;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;


@Service
public class HistoryServiceImpl implements HistoryService {
    @Resource
    private HistoryDao historyDao;

    @Override
    public R save(HistoryAddDto historyAddDto, int token) {
        if (historyAddDto != null){
            History history = new History();
            BeanUtils.copyProperties(historyAddDto, history);
            history.setUid(token);
            if(historyDao.insert(history) > 0){
                return R.ok();
            }
        }
        return R.fail();
    }

    @Override
    public R queryByUid(int uid) {
        if (uid >= 0){
            List<History> histories = historyDao.selectList(new QueryWrapper<History>().eq("uid", uid));
            if(histories != null){
                return R.ok(histories);
            }
        }
        return R.fail();
    }
}
